.nav{:style=>"float:left;"}
  = link_to 'เปลี่ยนสิทธิ', :controller => :main, :action => :change_role
.search{:style=>"float:right;font-size:8pt;"}
  - form_tag "#" do
    = text_field_tag :search
    = submit_tag "ค้นหา"
.role_pane{:style=>"margin-top:3em;"}
  %table{:width => '100%'}
    %tr
      %th login
      %th role
      %th ดำเนินการ
      %th เปลี่ยนสิทธิ
    - i = 0
    - @users.each do |user|
      - i+=1
      %tr
        - form_remote_tag :update => 'role_div'+i.to_s, :html => {:id => 'form'+i.to_s}, :url => {:controller=>'main', :action=>'assign_role'}, :success => "document.getElementById('status"+i.to_s+"').innerHTML = '<font color=green>บันทึกแล้ว</font>'", :failure => "document.getElementById('status"+i.to_s+"').innerHTML = '<font color=orange>เกิดความผิดพลาด</font>'" do
          %td= user.login
          %td
            %div{:id=>'role_div'+i.to_s}
              = hidden_field_tag :user_id, user.id
              = hidden_field_tag :row_id, i
              = check_box_tag("Admin", "A", (user.role!=nil && user.role.include?("A")), :onclick => "document.getElementById('status"+i.to_s+"').innerHTML='&nbsp;'") + 'Admin'
              = check_box_tag("Teacher", "T", (user.role!=nil && user.role.include?("T")), :onclick => "document.getElementById('status"+i.to_s+"').innerHTML='&nbsp;'") + 'Teacher'
              = check_box_tag("Dloc", "D", (user.role!=nil && user.role.include?("D")), :onclick => "document.getElementById('status"+i.to_s+"').innerHTML='&nbsp;'") + 'Student'
          %td
            %div{:id=>'status'+i.to_s}
              &nbsp;
          %td= submit_tag 'บันทึก', :onclick => remote_function(:update => 'status'+i.to_s, :url => {:controller => 'main', :action => 'assign_role'}, :with => "'user_id='+$('form#{i.to_s}').user_id.value+'&row_id='+$('form#{i.to_s}').row_id.value+(($('form#{i.to_s}').Admin.checked)?'&Admin='+$('form#{i.to_s}').Admin.value:'')+(($('form#{i.to_s}').Teacher.checked)?'&Teacher='+$('form#{i.to_s}').Teacher.value:'')+(($('form#{i.to_s}').Dloc.checked)?'&Dloc='+$('form#{i.to_s}').Dloc.value:'')", :success => "document.getElementById('status"+i.to_s+"').innerHTML = '<font color=green>บันทึกแล้ว</font>'", :failure => "document.getElementById('status"+i.to_s+"').innerHTML = '<font color=orange>เกิดความผิดพลาด</font>'")+";return false;"
= will_paginate @users, :previous_label => '&laquo; หน้าก่อน', :next_label => 'หน้าถัดไป &raquo;'
